package api

import (
	"day20/api/hander"
	"day20/pkg"
	"github.com/gin-gonic/gin"
)

func LoadRouters(r *gin.Engine) {

	//r.Use(Cors())
	r.Use(Cors())
	api := r.Group("/api")
	{
		api.POST("/register", hander.Register)
		api.POST("/login", hander.Login)

		api.POST("/create", hander.CreateLiveRoom)
		api.GET("/list", hander.ListLiveRoom)
		api.GET("/info", hander.InfoLiveRoom)
		api.POST("/update", hander.UpdateRoom)
		api.Use(pkg.JWTAuth("2210a"))
		api.GET("/chat", hander.Chat)

	}

}

func Cors() gin.HandlerFunc {

	return func(c *gin.Context) {

		c.Header("Access-Control-Allow-Origin", "*")

	}
}

//func Cors() gin.HandlerFunc {
//	return func(c *gin.Context) {
//		c.Header("Access-Control-Allow-Origin", "*")
//	}
//}
